# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Jeffrey Zhang <zhang.lei.fly@gmail.com>

_name=esbonio
pkgname=python-esbonio
pkgver=0.16.1
pkgrel=2
pkgdesc='Language server for working with Sphinx projects'
arch=('any')
url=https://github.com/swyddfa/esbonio
license=('MIT')
depends=('python-appdirs' 'python-sphinx' 'python-pygls' 'python-pyspellchecker'
         'python-setuptools' 'python-typing_extensions')
makedepends=('python-build' 'python-installer' 'python-setuptools'
             'python-wheel')
checkdepends=('python-pytest-lsp' 'python-pytest-timeout')
source=("$url/archive/esbonio-language-server-v$pkgver/$_name-$pkgver.tar.gz")
b2sums=('7808385bc803d6ce34371b3e86ba827910ff9608df3ce0ad54e7b2fd4ca2c23851332dd54c80752d2d99602d2f4615495c73bdc0fd51d2da6d63f1945b7fadf8')

build() {
  cd esbonio-esbonio-language-server-v$pkgver/lib/esbonio
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd esbonio-esbonio-language-server-v$pkgver/lib/esbonio
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  PATH="$PWD/test-env/bin:$PATH" test-env/bin/python -m pytest
}

package() {
  cd esbonio-esbonio-language-server-v$pkgver/lib/esbonio
  python -m installer --destdir="$pkgdir" dist/*.whl

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/$_name-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
